package cn.sc.summer.calculate.service.impl;

import cn.hutool.core.util.StrUtil;
import cn.sc.summer.calculate.form.GetSysTaskLogForm;
import cn.sc.summer.calculate.mapper.SysTaskLogMapper;
import cn.sc.summer.calculate.po.SysTaskLog;
import cn.sc.summer.calculate.service.SysTaskLogService;
import cn.sc.summer.calculate.vo.SysTaskLogVO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import cn.sc.summer.constant.model.PageResult;
import cn.sc.summer.mybatis.annotation.dynamicdatasource.DataSource;
import cn.sc.summer.mybatis.enums.DataSourceEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 类名：定时任务日志操作
 *
 * @author a-xin
 * @date 2024/4/3 17:28
 */
@Slf4j
@Service
public class SysTaskLogServiceImpl implements SysTaskLogService {

    @Resource
    private SysTaskLogMapper sysTaskLogMapper;

    /**
     * 分页获取定时任务执行日志
     *
     * @param form 查询表单
     * @return 日志信息
     */
    @Override
    @DataSource(DataSourceEnum.POST_GRE_SQL)
    public PageResult<SysTaskLogVO> getSysTaskLog(GetSysTaskLogForm form) {
        return sysTaskLogMapper.selectPage(form, new LambdaQueryWrapper<SysTaskLog>()
                        .eq(StrUtil.isNotBlank(form.getJobName()), SysTaskLog::getJobName, form.getJobName())
                        .eq(StrUtil.isNotBlank(form.getJobGroup()), SysTaskLog::getJobGroup, form.getJobGroup())
                        .eq(StrUtil.isNotBlank(form.getBeanClass()), SysTaskLog::getBeanClass, form.getBeanClass())
                        .eq(StrUtil.isNotBlank(form.getHandleIp()), SysTaskLog::getHandleIp, form.getHandleIp()),
                SysTaskLogVO.class);
    }

}
